import { isShowButton } from '@/utils/util';
import { getTenantId } from '@/access';

const tenantId = getTenantId();
export const columns = ({ handleEdit, categoryList, currentPermissions }) => [
  {
    title: '类目ID',
    dataIndex: 'id',
    search: false,
  },
  {
    title: '一级类目',
    dataIndex: 'parentArray',
    search: false,
    render: (txt, record) => {
      if (record?.level === 1) {
        return categoryList.find((item) => item?.id === record?.id)?.categoryName;
      } else {
        const arr = txt.split(',');
        return categoryList.find((item) => String(item?.id) === arr?.[0])?.categoryName;
      }
    },
  },
  {
    title: '二级类目',
    dataIndex: 'parentArray',
    search: false,
    render: (txt, record) => {
      if (record?.level < 2) {
        return '-';
      }
      if (record?.level === 2) {
        return categoryList.find((item) => item?.id === record?.id)?.categoryName;
      }
      if (record?.level > 2) {
        const arr = txt.split(',');
        return categoryList.find((item) => String(item?.id) === arr?.[1])?.categoryName;
      }
    },
  },
  {
    title: '三级类目',
    dataIndex: 'parentArray',
    search: false,
    render: (txt, record) => {
      if (record?.level < 3) {
        return '-';
      } else {
        return categoryList.find((item) => item?.id === record?.id)?.categoryName;
      }
    },
  },
  {
    title: '类目名称',
    dataIndex: 'categoryName',
    hideInTable: true,
  },
  {
    title: '类目等级',
    dataIndex: 'level',
    valueType: 'select',
    fieldProps: {
      options: [
        { label: '一级类目', value: 1 },
        { label: '二级类目', value: 2 },
        { label: '三级类目', value: 3 },
      ],
    },
    // render: (text) => {
    //   return categoryList.find((item) => item.id === text)?.categoryName || '';
    // },
  },
  {
    title: '是否叶子类目',
    dataIndex: 'leafOrder',
    search: false,
    valueType: 'select',
    fieldProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 2 },
      ],
    },
  },
  {
    title: '商品数量',
    dataIndex: 'count',
    search: false,
  },
  {
    title: '审批状态',
    dataIndex: 'isApprove',
    search: false,
    render: (txt, record) => {
      if (record?.isApprove == 1) {
        return '待审批';
      } else if (record?.isApprove == 3) {
        return '驳回';
      }else if (record?.isApprove == 0){
        return '同意'
      }
    },
  },
  {
    title: '备注',
    dataIndex: 'refusal',
    search: false,
  },
  {
    title: '操作',
    fixed: 'right',

    search: false,
    valueType: 'option',
    key: 'option',
    render: (_, record) => (
      <div>
        {tenantId === '9999' && record?.isApprove == 1 && (
          <a type="link" style={{ marginRight: 8 }} size="small" onClick={() => handleEdit('agree', record)}>
            同意
          </a>
        )}
        {tenantId === '9999' && record?.isApprove == 1 && (
          <a type="link" size="small" onClick={() => handleEdit('unAgree', record)}>
            驳回
          </a>
        )}
      </div>
    ),
  },
];
